$(document).ready(function() {
    $("#port_of_call").change(function() {
        var port_id = $(this).val();
        $.ajax({
            url: base_url + "/service/getbuoys",
            data: {pid : port_id},
            success:function(resp) {
                resp = $.parseJSON(resp);
                var options = "";
                for (i = 0; i < resp.length; i++) {
                    options += "<option value='" + resp[i].id + "'>" + resp[i].name + "</option>";
                }
                $("#buoy_name").html(options);
            }
        });
    });
    
    $(".datetime").datepicker({
        altFormat: '@',
        dateFormat: "dd/mm/yy"
    });
    
    $.validator.addMethod("requireSelect", function(value, element, arg) {
        return value != -1;
    }, "Please choose this field");
    
    $("#general_info").validate({
        rules: {
            'ship_name': { required: true },
            'customer_name': {requireSelect: true },
            'port': { requireSelect: true },
            'buoy': { requireSelect: true },
            'cargo_quantity': { required: true }
        }
    });
});

$(window).load(function(){
   var left_height = $(".cleft").height(); 
   var right_height = $(".cright").height();
   if (left_height < right_height) {
       $(".cleft").height(right_height);
   }
});